package com.xxl.api.admin.controller;

import com.xxl.api.admin.core.model.ReturnT;
import com.xxl.api.admin.core.model.XxlApiParameterType;
import com.xxl.api.admin.dao.XxlApiParameterTypeDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/5/18.
 */
@Controller
@RequestMapping("/type")
public class XxlApiParameterTypeController {

    @Resource
    private XxlApiParameterTypeDao xxlApiParameterTypeDao;

    @RequestMapping("/selectAll")
    @ResponseBody
    public Object selectAll(){
        List<XxlApiParameterType> list=xxlApiParameterTypeDao.selectAll();
        return list;
    }

    @RequestMapping("/add")
    @ResponseBody
    public ReturnT<String> add(XxlApiParameterType xxlApiParameterType){
        XxlApiParameterType xxlApiParameterType1=xxlApiParameterTypeDao.selectByType(xxlApiParameterType.getType());
        if(xxlApiParameterType1 != null){
            return new ReturnT<String>(ReturnT.FAIL_CODE, "该参数类型已存在，您可以直接在下拉框中选择");
        }
        int ret = xxlApiParameterTypeDao.add(xxlApiParameterType);
        return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
    }

}
